home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtoyc01.zip / VIDEO.CPP < prev    next >
C/C++ Source or Header  |  1994-01-12  |  12KB  |  510 lines

  1. /***************************************************************************
  2.   Video
  3.   Video mode routines, trial and error legal mode detection
  4.   PJB August 29, 1993, Internet mail to d91-pbr@nada.kth.se
  5.   Copyright 1993, All Rights Reserved
  6.   Free source, use at your own risk.
  7.   If modified, please state so if you pass this around.
  8.  
  9.   Intended for Turbo Vision, easily rehacked.
  10.  
  11.   ■ Use checkVideoType to initialize before you call any
  12.     other procedures or access any variables in this unit.
  13.  
  14.   ■ Use scanEVGAModes only on EGA and VGA compatible cards, or else
  15.     the results might be misleading. Check this before you use
  16.     scanEVGAModes.
  17.  
  18.   If the video card is VERY old, the computer might crash since the
  19.   BIOSes weren't designed to handle "illegal" video modes back then...
  20.  
  21.   For full VESA, Video7 support, use only setSpecialVideoMode and
  22.   getSpecialVideoMode from this unit.
  23.  
  24.   You can overlay this unit.
  25.   See CONFIG.PAS for a description of all conditional defines.
  26.  
  27. ***************************************************************************/
  28.  
  29. #define Uses_TCommandSet
  30.  
  31. #include <tv.h>
  32. #include <dos.h>
  33. #include <views.h>
  34.  
  35. #include "video.h"
  36. #include "vesa.h"
  37.  
  38.  
  39. ushort Seg0040 = 0x0040;
  40. ushort SegB000 = 0xB000;
  41. ushort SegB800 = 0xB800;
  42.  
  43.  
  44. Boolean video7;
  45. VideoTypes videoType;
  46. #ifdef TOYVESASUPPORT
  47.  ushort dontClearVideoModeFlag = 0x80;
  48. #endif
  49. SpecialVideoTypes videoTypesToCheck = vtVesa | vtVideo7;
  50.  
  51.  
  52. ModeSet initVGAModes()
  53. {
  54.   ModeSet temp;
  55.  
  56.   for (int i=0; i<256; i++)
  57.     temp.disableCmd(i);
  58.   temp.enableCmd(2);
  59.   temp.enableCmd(3);
  60.   temp.enableCmd(7);
  61.   return temp;
  62. }
  63.  
  64. ModeSet initStandardTextModes()
  65. {
  66.   ModeSet temp=initVGAModes();
  67.  
  68.   temp.enableCmd(8);
  69.   for (int i=20; i<256; i++)
  70.     temp.enableCmd(i);
  71.   return temp;
  72. }
  73.  
  74. ModeSet initVESAModes()
  75. {
  76.   ModeSet temp;
  77.  
  78.   for (int i=0; i<256; i++)
  79.     temp.disableCmd(i);
  80.   for (i=8; i<0xD; i++)
  81.     temp.enableCmd(i);
  82.   return temp;
  83. }
  84.  
  85. ModeSet standardTextModes = initVGAModes();
  86. ModeSet vgaModes          = initStandardTextModes();
  87. ModeSet vesaModes       = initVESAModes();
  88.  
  89.  
  90.  #ifdef TOYVIDEO7SUPPORT
  91.   /*******************************************************************
  92.     Test for the presence of a Video7 or HP video card
  93.   *******************************************************************/
  94.   uchar v7orHPInstalled()
  95.   {
  96.     asm {
  97.     mov  ax,0x6F00
  98.     xor  bx,bx
  99.     int  0x10
  100.  
  101.     mov  al,V7Installed
  102.     cmp  bx,'V7'
  103.     je   Fin
  104.  
  105.     mov  al,HPInstalled
  106.     cmp  bx,'HP'
  107.     je   Fin
  108.  
  109.     mov  al,0
  110.     }
  111.       Fin:
  112.     return _AL;
  113.   }
  114.  #endif
  115.  
  116.  
  117.   /*******************************************************************
  118.     Set video mode using VESA, Video7 or BIOS, if supported and present
  119.   *******************************************************************/
  120.   void setSpecialVideoMode(ushort mode)
  121.   {
  122.     asm {
  123.         mov  ax,mode
  124.  
  125.        #ifdef TOYVESASUPPORT
  126.     cmp  vesaVersion,0
  127.         je   noVesa
  128.     }
  129.     setVesaMode(mode);
  130.     asm {
  131.     cmp  al,0x4F               /* Supported? */
  132.         je   fin
  133.  
  134.         mov  bx,mode
  135.     test bh,0x7F
  136.         jne  fin
  137.  
  138.     mov  al,bh
  139.     and  al,0x80
  140.     or   al,bl
  141.        #endif
  142.     }
  143.  
  144.       noVesa:
  145.     asm {
  146.        #ifdef TOYVIDEO7SUPPORT
  147.         cmp  video7,False
  148.     je   go
  149.     mov  bl,al
  150.     mov  ax,0x6F05
  151.        #endif
  152.     }
  153.  
  154.       go:
  155.     asm {
  156.     int  0x10
  157.     }
  158.       fin:
  159.   }
  160.  
  161.  
  162.   /*******************************************************************
  163.     Retrive current video from VESA, Video7 or plain BIOS
  164.   *******************************************************************/
  165.   ushort getSpecialVideoMode()
  166.   {
  167.     asm {
  168.        #ifdef TOYVESASUPPORT
  169.         cmp  vesaVersion,0
  170.         je   noVesa
  171.     }
  172.     getVesaMode();
  173.     asm{
  174.     and  ah,0x7F
  175.  
  176.     #ifdef toyV7UniVesaKludge
  177.          #ifdef TOYVIDEO7SUPPORT
  178.           cmp  video7,False
  179.           je   noV7Test
  180.      #endif
  181.      cmp  ax,1         /* Boring bad VESA driver returns this on V7 */
  182.          je   noVesa
  183.     }
  184.  
  185.       noV7Test:
  186.     asm {
  187.     #endif
  188.  
  189.     cmp  bx,0x4F                 /* Success? */
  190.         je   fin
  191.     }
  192.  
  193.       noVesa:
  194.     asm {
  195.        #endif
  196.  
  197.        #ifdef TOYVIDEO7SUPPORT
  198.         cmp  video7,False
  199.         je   noV7
  200.  
  201.     mov  ax,0x6F04
  202.     int  0x10
  203.  
  204.         jmp  clearAH
  205.        #endif
  206.     }
  207.  
  208.       noV7:
  209.     asm {
  210.     mov  ah,0x0F
  211.     int  0x10
  212.     }
  213.  
  214.       clearAH:
  215.     asm {
  216.     and  ax,0x7F
  217.     }
  218.       fin:
  219.     return _AX;
  220.   }
  221.  
  222.  
  223.   /*******************************************************************
  224.     Vesa present?
  225.   *******************************************************************/
  226.  #ifdef TOYVESASUPPORT
  227.   void checkVesa()
  228.   {
  229.     detectVesaVersion();
  230.     if (vesaVersion)
  231.       dontClearVideoModeFlag=0x8000;
  232.   }
  233.  #endif
  234.  
  235.  
  236.   /*******************************************************************
  237.     Video 7 card?
  238.   *******************************************************************/
  239.  #ifdef TOYVIDEO7SUPPORT
  240.   void checkVideo7()
  241.   {
  242.     video7=Boolean(v7orHPInstalled()!=0);
  243.   }
  244.  #endif
  245.  
  246.  
  247.   /*******************************************************************
  248.     EGA, VGA or Other?
  249.   *******************************************************************/
  250.   void checkEVGA()
  251.   {
  252.     asm {
  253.     push bp
  254.  
  255.         mov  videoType,OTHER
  256.     mov  ax,0x1200
  257.     mov  bx,0x10
  258.     mov  cx,0xFFFF
  259.     int  0x10
  260.  
  261.     inc  cx
  262.         je   fin               /* No EGA support */
  263.  
  264.         mov  videoType,EGA
  265.  
  266.     mov  ax,0x1A00
  267.     int  0x10
  268.     cmp  al,0x1A
  269.         jne  fin               /* Not a VGA or PS/2 type card */
  270.  
  271.     cmp  bl,7
  272.     jae  vga               /* VGA, MCGA */
  273.  
  274.     cmp  bl,4               /* EGA */
  275.         jae  fin
  276.  
  277.     mov  videoType,OTHER    /* Something else */
  278.         jmp  fin
  279.     }
  280.       vga:
  281.     asm {
  282.         mov  videoType,VGA
  283.     }
  284.       fin:
  285.     asm {
  286.     pop  bp
  287.     }
  288.   }
  289.  
  290.  
  291.   /*******************************************************************
  292.     Check which of VESA, Video7, VGA and EGA are present
  293.   *******************************************************************/
  294.   void checkVideoType()
  295.   {
  296.    #ifdef TOYVESASUPPORT
  297.     if (videoTypesToCheck & vtVesa)
  298.       checkVesa();
  299.    #endif
  300.    #ifdef TOYVIDEO7SUPPORT
  301.     if (videoTypesToCheck & vtVideo7)
  302.       checkVideo7();
  303.    #endif
  304.     checkEVGA();
  305.   }
  306.  
  307.  
  308.   /*******************************************************************
  309.     Calculate the video mode's number of scan lines
  310.   *******************************************************************/
  311.   int getCurrentScanLines()
  312.   {
  313.     asm {
  314.     mov  es,Seg0040
  315.         mov  al,es:[crtRows]
  316.     inc  al
  317.         mov  ah,es:[crtPoints]
  318.     mul  ah
  319.     }
  320.     return _AX;
  321.   }
  322.  
  323.  
  324.   /*******************************************************************
  325.      Change to another font on the video card
  326.      Available fonts are:
  327.        8x8:  EGA, VGA         (Internal8x8Font)
  328.        8x14: EGA, VGA         (Internal8x14Font)
  329.        8x16:      VGA         (Internal8x16Font)
  330.   *******************************************************************/
  331.   void useInternalFont(uchar font)
  332.   {
  333.     asm {
  334.     push bp
  335.     mov  ah,0x11
  336.         mov  al,font
  337.     mov  bl,0
  338.     int  0x10
  339.     pop  bp
  340.     }
  341.   }
  342.  
  343.  
  344.   /*******************************************************************
  345.     Define your own characters
  346.     Points: Character height
  347.     First: First char to define
  348.     Count: Chars to define
  349.     Font points to an array of character bitmaps,
  350.     ASCII <First> first, <Points> bytes per char, top to bottom.
  351.   *******************************************************************/
  352.   void loadUserFont(uchar points, int first, int count, void *font)
  353.   {
  354.  #ifdef DPMI
  355.     void *real, *protected;
  356.  
  357.     if GetDosMem(Real, Protected, Points*Count) then
  358.     {
  359.       MemMove(Font, Protected, Points*Count);
  360.  #endif
  361.       asm {
  362.     push bp
  363.     mov  ax,0x1110
  364.     mov  bl,0                 // First definition block
  365.         mov  bh,points
  366.         mov  cx,count
  367.         mov  dx,first
  368.        #ifdef DPMI
  369.     mov  RealRegs.RealEBP.Word,0
  370.  
  371.     mov  si,Real.Word+2
  372.     mov  RealRegs.RealES.Word,si
  373.  
  374.     push 0x10
  375.     call RealModeInterrupt
  376.        #else
  377.         les